//
//  KindFilterTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-11-23.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "KindFilterTableViewCell.h"
#import "Grouble.h"
#import "MerchantCataGroupModel.h"

@interface KindFilterTableViewCell ()
{
    UIImageView *_imageView;
    UILabel *_nameLabel;
    UIButton *_numberBtn;
}

@end
@implementation KindFilterTableViewCell
+(instancetype)KindFilterTableViewCell:(UITableView *)tableView
{
    static NSString *menuID = @"kindfilter";
    KindFilterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:menuID];
    if (cell == nil) {
        cell = [[KindFilterTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:menuID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 30)];
        _nameLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_nameLabel];
        
        _numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _numberBtn.frame = CGRectMake(self.frame.size.width-85, 12, 80, 15);
        _numberBtn.titleLabel.font = [UIFont systemFontOfSize:11];
        _numberBtn.layer.cornerRadius = 7;
        _numberBtn.layer.masksToBounds = YES;
        [_numberBtn setBackgroundImage:[UIImage imageNamed:@"film"] forState:UIControlStateNormal];
        [_numberBtn setBackgroundImage:[UIImage imageNamed:@"film"] forState:UIControlStateHighlighted];
        [_numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_numberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [self.contentView addSubview:_numberBtn];
        
        //下划线
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-0.5, self.frame.size.width, 0.5)];
        lineView.backgroundColor = ZCJColor(192, 192, 192);
        [self.contentView addSubview:lineView];
        // Initialization code
    }
    return self;
}
- (void)setMerchantCataGroupModel:(MerchantCataGroupModel *)merchantCataGroupModel
{
    _merchantCataGroupModel = merchantCataGroupModel;
    _nameLabel.text = merchantCataGroupModel.name;
    
    if (merchantCataGroupModel.list == nil) {
        if([merchantCataGroupModel.id integerValue] != 0){
            [_numberBtn setTitle:[NSString stringWithFormat:@"%d", [merchantCataGroupModel.id integerValue]
                                  ] forState:UIControlStateNormal];
        }
       
    }else{
        if ([merchantCataGroupModel.id integerValue] != 0) {
            [_numberBtn setTitle:[NSString stringWithFormat:@"%d>",[merchantCataGroupModel.id integerValue]] forState:UIControlStateNormal];
        }
    }
    
    NSString *str = [NSString stringWithFormat:@"%d>",[merchantCataGroupModel.id integerValue]];
    CGSize textSize = [str sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(80, 15) lineBreakMode:NSLineBreakByWordWrapping];
    
    _numberBtn.frame = CGRectMake(self.frame.size.width-10-textSize.width-10, 12, textSize.width+10, 15);

   
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
